#version 330 core

uniform sampler2D diffuseTexture;
uniform sampler2D specularTexture;
uniform vec3 viewPos;
uniform vec3 lightDirection;
uniform vec4 lightColor;
uniform vec4 ambientColor;

in VsOut
{
	vec3 position;
	vec3 normal;
    vec2 uv;
} vsIn;

out vec4 fragColor;

void main()
{
	vec3 lightDir = normalize(-lightDirection.xyz);
	vec3 normal = normalize(vsIn.normal);
	float diffuse = max(dot(normal, lightDir), 0.0);
	
	vec3 viewDir = normalize(viewPos.xyz - vsIn.position);
	vec3 reflectLightDir = reflect(-lightDir, normal);
	float spec = pow(max(dot(reflectLightDir, viewDir), 0), 10);
	
	vec4 diffuseColor = texture(diffuseTexture, vsIn.uv);
	vec4 sepcularColor = texture(specularTexture, vsIn.uv);
	
    fragColor = lightColor * (diffuseColor * ambientColor + diffuseColor * diffuse + sepcularColor * spec);
}
